package com.songcan.gateway.vo;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.cloud.gateway.filter.FilterDefinition;
import org.springframework.cloud.gateway.handler.predicate.PredicateDefinition;
import org.springframework.cloud.gateway.route.RouteDefinition;

import javax.validation.constraints.NotEmpty;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class CustomRouteDefinitionVO {


    private String id;
    @NotEmpty(message = "uri 不能为空")
    private String uri;
    @NotEmpty(message = "匹配条件不能为空")
    private List<PredicateDefinition> predicates;
    private List<FilterDefinition> filters;
    private Map<String, Object> metadata = new HashMap<>();
    private Integer order;
    private Integer enabled = 1;

    public CustomRouteDefinitionVO(RouteDefinition route) {
        this.id = route.getId();
        this.uri = route.getUri().toString();
        this.predicates = route.getPredicates();
        this.filters = route.getFilters();
        this.metadata = route.getMetadata();
        this.order = route.getOrder();
        this.enabled = 1;
    }

    public CustomRouteDefinitionVO(){

    }






    @Override
    public String toString() {
        return "GatewayDefine{" +
                "id='" + id + '\'' +
                ", uri='" + uri + '\'' +
                ", predicates='" + predicates + '\'' +
                ", filters='" + filters + '\'' +
                '}';
    }
}
